{extend name="base" /}
{block name="body"}

<div class="am-padding am-padding-bottom-0">
	<strong class="am-text-primary am-text-lg">文档管理</strong> / <small>添加</small>
</div>

<div class="am-padding am-btn-toolbar">
	<div class="am-btn-group am-btn-group-xs">
		<a href="{:url('admin/Archives/index')}" class="am-btn am-btn-default"><span class="am-icon-plus"></span> 列表</a>
		<a href="{:url('admin/Archives/add')}" class="am-btn am-btn-default"><span class="am-icon-plus"></span> 新增</a>
	</div>
</div>

<form class="am-form" action="{:url('admin/Archives/add')}" method="post">
	<fieldset>

		<div class="am-g">
			<div class="am-u-md-6">
				<div class="am-form-group">
					<div class="am-input-group">
						<span class="am-input-group-label">所属栏目</span>
						<select name="category_id" class="am-form-field">
							{foreach name="category_list_tree" item="vo"}
							<option value="{$vo.id}" {eq name="$category_id" value="$vo.id"}selected{/eq} {eq name="$vo.type" value="0"}disabled{/eq}>{$vo.title}</option>
							{/foreach}
						</select>
					</div>
				</div>

				<div class="am-form-group">
					<div class="am-input-group">
						<span class="am-input-group-label">标题</span>
						<input type="text" name="title" class="am-form-field" placeholder="请输入标题">
					</div>
				</div>



				<div class="am-form-group">
					<div class="am-input-group">
						<span class="am-input-group-label">关键词</span>
						<input type="text" name="keywords" class="am-form-field" placeholder="请输入关键词">
					</div>
				</div>
				<div class="am-form-group">
					<div class="am-input-group">
						<span class="am-input-group-label">描述</span>
						<textarea name="description" rows="5" placeholder="描述"></textarea>
					</div>
				</div>

			</div>
			<div class="am-u-md-6">

				<div class="am-g">
					<div class="am-u-sm-6">
						<div class="am-form-group">
							<div class="am-input-group">
								<span class="am-input-group-label">作者</span>
								<input type="text" name="author" class="am-form-field" placeholder="请输入作者">
							</div>
						</div>
					</div>
					<div class="am-u-sm-6">
						<div class="am-form-group">
							<div class="am-input-group">
								<span class="am-input-group-label">来源</span>
								<input type="text" name="source" class="am-form-field" placeholder="请输入作者">
							</div>
						</div>
					</div>
				</div>
					

				<div class="am-g">
					<div class="am-u-sm-6">
						<div class="am-form-group">
							<div class="am-input-group">
								<span class="am-input-group-label">排序</span>
								<input type="number" name="sort" class="am-form-field" placeholder="排序">
							</div>
						</div>
					</div>
					<div class="am-u-sm-6">
						<div class="am-form-group">
							<div class="am-input-group">
								<span class="am-input-group-label">点击量</span>
								<input type="number" name="hits" class="am-form-field" placeholder="点击量">
							</div>
						</div>
					</div>
				</div>

				<div class="am-form-group">
					<div class="am-input-group">
						<span class="am-input-group-label">阅读权限</span>
						<div class="am-form-field">
							<label class="am-checkbox-inline">
								<input type="checkbox" name="permission" value="0" data-am-ucheck> 游客
							</label>
							<label class="am-checkbox-inline">
								<input type="checkbox" name="permission" value="1" data-am-ucheck> 普通会员
							</label>
							<label class="am-checkbox-inline">
								<input type="checkbox" name="permission" value="2" data-am-ucheck> VIP会员
							</label>
						</div>

					</div>
				</div>
	

				<div class="am-form-group">
					<div class="am-input-group">
						<span class="am-input-group-label">状态</span>
						<div class="am-form-field">
							<label class="am-radio-inline">
								<input type="radio" name="status" value="1" data-am-ucheck checked> 正常
							</label>
							<label class="am-radio-inline">
								<input type="radio" name="status" value="0" data-am-ucheck> 禁用
							</label>
						</div>
					</div>
				</div>
			</div>
		</div>

		<div class="am-g">
			<div class="am-u-sm-12">

				<ul id="gallery-list" data-am-widget="gallery" class="am-gallery am-avg-sm-3 am-avg-md-6 am-avg-lg-10 am-gallery-default am-gallery-upload" data-am-gallery="{ pureview: true }" >
				</ul>

				<div class="am-form-group am-form-file">
					<button type="button" class="am-btn am-btn-danger am-btn-sm">
					<i class="am-icon-cloud-upload"></i> 选择要上传的文件</button>
					<input id="form-file-upload" type="file" multiple>
				</div>

			</div>
		</div>


		<div class="am-g">
			<div class="am-u-sm-12">
				<div class="am-form-group">
					<div class="am-input-group">
						<span class="am-input-group-label">内容</span>
						<div id="wangeditor"></div>
						<textarea id="ipt-wangeditor" name="content" class="am-hide"></textarea>
					</div>
				</div>
		
				<p><button type="reset" class="am-btn am-btn-default">重置</button> <button type="submit" lay-submit lay-filter="submit" class="am-btn am-btn-default">保存</button></p>
			</div>
		</div>

	</fieldset>
</form>
         

{/block}

{block name="siderbar"}
	<div class="sidebar-nav nav-Content am-in">
		{notempty name="category_list_tree"}
		<ul class="am-list admin-sidebar-list">
			{volist name="category_list_tree" id="vo"}
			<li><a {eq name="$vo.type" value="1"}href="{:url('admin/Archives/lists',['category_id'=>$vo['id']])}"{else/}class="am-disabled"{/eq}>{notempty name="$vo.icon"}<img src="{$vo.icon}" class="category-icon">{/notempty} {$vo.title}</a></li>
			{/volist}
		</ul>
		{/notempty}
	</div>
{/block}

{block name="js"}
	<script type="text/javascript" src="/static/lib/wangEditor/wangEditor.js"></script>
{/block}
{block name="script"}

<script type="text/javascript">
	var E = window.wangEditor;

	var editor = new E('#wangeditor');
	editor.customConfig.debug = location.href.indexOf('wangeditor_debug_mode=1') > 0;
	editor.customConfig.uploadImgServer = "{:url('api/Upload/wangEditer')}";
	editor.customConfig.uploadImgMaxSize = 3 * 1024 * 1024;
	editor.customConfig.customAlert = function (info) {
		layer.msg(info);
	}

	var iptWangeditor = $('#ipt-wangeditor');

	editor.customConfig.onchange = function (html) {
		// 监控变化，同步更新到 textarea
		iptWangeditor.val(html);
	}

	editor.create();
	
	iptWangeditor.val(editor.txt.html());
	

	$(function() {
		$('#form-file-upload').on('change', function() {
			
			$.each(this.files, function() {

				var formData = new FormData();
				formData.append("file",this);
				formData.append("purpose",'archives');

				$.ajax({
					url: "{:url('api/upload/index')}",
					type: 'post',
					data: formData,
					contentType: false,
					processData: false,
					async: true,
					success: function(info) {
						//layer.close(loading);
						
						if (info.code == 1) {
							var fileNames = '';
							fileNames += '<li>';
							fileNames += '	<div class="am-gallery-item">';
							fileNames += '		<div class="image">';
							fileNames += '			<img src="' + info.thumb + '" data-rel="' + info.url + '" alt=""/>';
							fileNames += '			<span class="delete"><i class="am-icon-times am-icon-fw"></i></span>';
							fileNames += '			<span class="forward"><i class="am-icon-arrow-left am-icon-fw"></i></span>';
							fileNames += '		</div>';
							fileNames += '		<input type="text" name="images[title][]" value="'+info.name+'" class="am-form-field" placeholder="请输入图片描述">';
							fileNames += '		<input type="hidden" name="images[id][]" value="'+info.id+'">';
							fileNames += '		<input type="hidden" name="images[name][]" value="'+info.name+'">';
							fileNames += '	</div>';
							fileNames += '</li>';
							$('#gallery-list').append(fileNames);
						} else {
							layer.msg(info.message, {
								icon: 2,
								shade: 0.3,
								anim: 1
							});
						}
						
					}
				});

				

			});
			
		});
	});


	$(document).on('click','#gallery-list li .forward',function(){
		var curr_Li = $(this).closest("li");
		var prev_li = curr_Li.prev();
		if(prev_li.length != 0){
			prev_li.before(curr_Li);
		}
	}) 

	$(document).on('click','#gallery-list li .delete',function(){
		$(this).closest("li").remove();
	}) 
</script>

{/block}


